#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n, a[N], ans;
bool b[N];

void dfs(int x, int s) {
    if (x == n) {
        ans = max(ans, s);
        return;
    }
    b[x] = 0;
    int k = x - 1;
    while (k >= 0) {
        if (b[k] == 0)
            break;
        k--;
    }
    if (k == -1)
        dfs(x + 1, s);
    else {
        if (a[k] == a[x])
            dfs(x + 1, s + a[k]);
        else
            dfs(x + 1, s);
    }
    b[x] = 1;
    k = x - 1;
    while (k >= 0) {
        if (b[k])
            break;
        k--;
    }
    if (k == -1)
        dfs(x + 1, s);
    else {
        if (a[k] == a[x])
            dfs(x + 1, s + a[k]);
        else
            dfs(x + 1, s);
    }
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        ans = 0;
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        dfs(0, 0);
        cout << ans << endl;
    }
    return 0;
}